package com.xing.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.xing.dao.PaymentDetailDao;
import com.xing.model.PaymentDetail;
import com.xing.util.Util;

@Service
public class PaymentDetailService {

	private static Logger logger = Logger.getLogger(PaymentDetailService.class);
	
	@Resource
	private PaymentDetailDao dao;
	
	public void setDao(PaymentDetailDao dao) {
		this.dao = dao;
	}
	
	public Map<String, Object> getPaymentDetail(int id) {
		
		logger.info("do getPaymentDetail");
		
		List<String> conditionList = new ArrayList<String>();
		conditionList.add("pd.intId=" + id);
		
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getListAndCount(conditionList, null, null).get("rows");
		if (!Util.isEmpty(list)) {
			return list.get(0);
		} else {
			return null;
		}
	}

	public void addPaymentDetail(PaymentDetail info) {
		
		dao.addPaymentDetail(info);
	}
	
	public void updatePaymentDetail(PaymentDetail info) {
		
		dao.updatePaymentDetail(info);
	}
	
	public void deletePaymentDetail(String idStr) {
		
		String[] arr = idStr.split(",");
		List<Integer> idList = new ArrayList<Integer>();
		for (String tmp : arr) {
			idList.add(Integer.parseInt(tmp));
		}
		
		dao.deletePaymentDetail(idList);
	}
	
	public Map<String, Object> getListAndCount(List<String> conditionList, int page, int pageRow) {
		
		return dao.getListAndCount(conditionList, page, pageRow);
	}
	
	public List<Map<String, Object>> getContractPaymentList(String contractId) {
		
		logger.info("do getContractPaymentList");
		
		return dao.getContractPaymentList(contractId);
	}
}
